package com.skm.open.sensitive.word.processor;

import com.skm.open.sensitive.word.processor.entity.KeyWord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import javax.annotation.PostConstruct;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author skqing
 */

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, JacksonAutoConfiguration.class })
public class SimpleApplication {

    @Autowired
    private SensitiveWordProcessor sensitiveWordProcessor;

    public static void main(String[] args) {
        SpringApplication.run(SimpleApplication.class, args);
    }

    @PostConstruct
    public void test() {
        String text1 = "这是一部黄色电影，也是一部AV电影";
        // 初始化敏感词
        Set<KeyWord> kws1 = new HashSet<KeyWord>();
        kws1.add(new KeyWord("黄色"));
        kws1.add(new KeyWord("AV"));


        KWSeeker kwSeeker = sensitiveWordProcessor.getKWSeeker("comment-sensitive-word");
        List<SensitiveWordResult> words1 = kwSeeker.findWords(text1);
        System.out.println("返回敏感词及下标：" + words1);
        String s1 = sensitiveWordProcessor.getKWSeeker("comment-sensitive-word").htmlHighlightWords(text1);
        System.out.println("html高亮：" + s1);
        String r1 = sensitiveWordProcessor.getKWSeeker("comment-sensitive-word").replaceWords(text1);
        System.out.println("字符替换：" + r1);
    }

}